package com.schoolcloud.front.controller;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.front.entity.UserFollow;
import com.schoolcloud.front.mapper.UserFollowMapper;
import com.schoolcloud.front.service.UserFollowService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/front/user/follow")
@RequiredArgsConstructor
public class UserFollowController {
    private final UserFollowService userFollowService;

    @PostMapping
    public R<?> saveUserFollow(@RequestBody UserFollow userFollow) {
        userFollowService.saveUserFollow(userFollow);
        return R.ok().setMsg("关注成功");
    }
    @DeleteMapping("{followId}")
    public R<?> deleteUserFollow(@PathVariable String followId) {
        userFollowService.lambdaUpdate().eq(UserFollow::getFollowerId,UserContext.getUserIdToLong())
                .eq(UserFollow::getFollowingId, followId).remove();
        return R.ok().setMsg("取消关注成功");
    }
}
